package com.xwqiang.controller;

import com.xwqiang.handle.AppException;
import com.xwqiang.pojo.dto.SysUserLoginDto;
import com.xwqiang.pojo.vo.SysUserLoginVo;
import com.xwqiang.service.SysUserService;
import com.xwqiang.utils.Resp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Slf4j
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @PostMapping("/login")
    public Resp<SysUserLoginVo> login(SysUserLoginDto sysUserLoginDto) throws AppException {
        log.info(sysUserLoginDto.toString());
        SysUserLoginVo SysUserLoginVo = sysUserService.login(sysUserLoginDto);
        return Resp.success(SysUserLoginVo);
    }

    @PreAuthorize("hasAuthority('admin:list')")
    @GetMapping("/list")
    public Resp list(){
        return Resp.success("list");
    }

    @PreAuthorize("hasAuthority('admin:add')")
    @GetMapping("/add")
    public Resp add(){
        return Resp.success("add");
    }

    @PreAuthorize("hasAuthority('admin:edit')")
    @GetMapping("/edit")
    public Resp edit(){
        return Resp.success("edit");
    }

    @PreAuthorize("hasAuthority('admin:del')")
    @GetMapping("/del")
    public Resp del(){
        return Resp.success("del");
    }

}
